home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / ENCRYPT.SWG / 0005_ENCRYPT2.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  1KB  |  38 lines

  1. {The following very simple routine will encrypt and decrypt a Text File a line
  2. at a time.  The CR/LF is left unencrypted and the algorithm ensures that no
  3. encrypted Character can be < asciiz 127 *provided that* the Text For encrypting
  4. has no hi-bit Characters.
  5.  
  6. Obviously this is just a skeleten example (untested) With no error checking but
  7. it should demonstrate what you need to do. After encrypting Text just reverse
  8. the parameters and run the Program again to decrypt the encrypted Text.
  9. }
  10. Program encrypt_Text;
  11.  
  12. Var
  13.   inText,
  14.   outText  : Text;
  15.   st       : String;
  16.  
  17. Function ConvertTxt(s: String): String;
  18.   Var x : Byte;
  19.   begin
  20.     ConvertTxt[0] := s[0];
  21.     For x := 1 to length(s) do
  22.       ConvertTxt[x] := chr(ord(s[x]) xor (Random(128) or 128));
  23.   end;  { ConvertTxt }
  24.  
  25. begin
  26.   RandSeed  := 1234567;{ set to whatever value you wish - this is your "key" }
  27.   assign(inText,ParamStr(1));
  28.   reset(inText);
  29.   assign(outText,ParamStr(2));
  30.   reWrite(outText);
  31.   While not eof(inText) do begin
  32.     readln(inText,st);
  33.     Writeln(outText,ConvertTxt(st));
  34.   end;
  35.   close(inText);
  36.   close(outText);
  37. end.
  38.